﻿@model PsCommand

@{
    ViewBag.Title = "คำสั่งโยกย้าย";
}

<div id="pnlHeader" style="margin-left:100px; margin-bottom:30px; width:1000px;">
<h2><span class="red">แก้ไข</span> คำสั่งโยกย้าย</h2>

@using (Html.BeginForm()) {
    @* @Html.AntiForgeryToken() *@
    @Html.ValidationSummary(true)

    <h4 class="header">แบบฟอร์มคำสั่งโยกย้าย</h4>

    <div class="detail">
        @Html.HiddenFor(model => model.CmdId)
        
        
        <table class="info">
            <tr>
                <td class="editor-label">

                </td>
                <td class="editor-field">
                    <span style="visibility:collapse"><label>@Html.RadioButtonFor(model => model.CmdFlag, "1") คำสั่งหน่วยงาน</label></span>
                    <label>@Html.RadioButtonFor(model => model.CmdFlag, "2") คำสั่งสรพ.</label>
                    <label>@Html.RadioButtonFor(model => model.CmdFlag, "3") คำสั่งกระทรวง</label>
                    @Html.ValidationMessageFor(model => model.CmdFlag)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.RecordStatus)
                </td>
                <td class="editor-field">
                    @Common.GetRecordStatusName(Model.RecordStatus)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.CmdTypeId)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.CmdTypeId)
                        //.Name("ddlCmdType")
                        .BindTo(new SelectList(new GERPContext(true).PsCommandTypes.Where(m => m.CmdGroupId == 2).ToList(), "CmdTypeId", "CmdTypeName"))
                        //.SelectedIndex(Model != null ? (Model.CmdTypeId != null ? Model.CmdTypeId.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                    )
                    @Html.ValidationMessageFor(model => model.CmdTypeId)
                </td>
            </tr>

            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.CmdName)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.CmdName)
                    @Html.ValidationMessageFor(model => model.CmdName)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.CmdRefNo)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.CmdRefNo)
                    @Html.ValidationMessageFor(model => model.CmdRefNo)
                </td>
            </tr>

            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.CmdDescr)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.CmdDescr)
                    @Html.ValidationMessageFor(model => model.CmdDescr)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.EmpTypeId)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.EmpTypeId)
                        .BindTo(new SelectList(new GERPContext(true).MasEmployeeTypes.ToList(), "EmpTypeId", "Name"))
                        //.SelectedIndex(Model != null ? (Model.EmpTypeId != null ? Model.EmpTypeId.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                    )
                    @Html.ValidationMessageFor(model => model.EmpTypeId)
                </td>
            </tr>

            @*<tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.PenaltyId)
                </td>
                <td class="editor-field">
                    @(Html.Telerik().ComboBoxFor(m => m.PenaltyId)
                        //.Name("ddlPenalty")
                        .BindTo(new SelectList(new GERPContext(true).hrm_dc_penalty.ToList(), "pen_seq", "pen_name"))
                        //.SelectedIndex(Model != null ? (Model.PenaltyId != null ? Model.PenaltyId.Value : -1) : -1)
                        .HighlightFirstMatch(true)
                        .Filterable(filtering => filtering.FilterMode(AutoCompleteFilterMode.Contains))
                        .ClientEvents(events => events.OnChange("ddlPenaltyChange").OnLoad("ddlPenaltyChange"))
                    )
                    @Html.ValidationMessageFor(model => model.PenaltyId)
                </td>
            </tr>*@
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.Remarks)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.Remarks)
                    @Html.ValidationMessageFor(model => model.Remarks)
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <h3>หัวรายงาน</h3>
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.CmdRptDate)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.CmdRptDate)
                    @Html.ValidationMessageFor(model => model.CmdRptDate)
                </td>
            </tr>
            <tr>
                <td class="editor-label">
                    @Html.LabelFor(model => model.RptHeader)
                </td>
                <td class="editor-field">
                    @Html.EditorFor(model => model.RptHeader)
                    @Html.ValidationMessageFor(model => model.RptHeader)
                </td>
            </tr>
        </table>
        <br />
        
    <p id="pnlCommand1">
        @if (Model.RecordStatus != "A" && Model.RecordStatus != "P")
        {
        <input type="submit" value="บันทึก" />@Html.Raw("&nbsp;&nbsp;")
        }
        @Html.ActionLink("กลับไปหน้าแสดงรายการทั้งหมด", "Index")
        
        @Html.Raw("&nbsp;&nbsp;|&nbsp;&nbsp;")
        @Html.ActionLink("กลับไปหน้าแสดงรายละเอียด", "Details", new { id = Model.CmdId })
        
    </p>
        <hr />
        @if (Model.RecordStatus != "A" && Model.RecordStatus != "P")
        {
        <h3><a id="lnkAddDetail" title="คลิกเพื่อเพิ่มรายชื่อบุคลากรในคำสั่ง"><img src="~/Images/Icons/add.png" height="14" /> เพิ่มรายชื่อในคำสั่ง</a></h3>
        }

        @if (Model != null)
        {
            <table class="tablesorter" style="width:100%">
                <thead>
                    <tr>
                        <th>
                            @Html.DisplayNameFor(model => model.HrmPsCommandDtls.HrmPsEmployees.FullName)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.HrmPsCommandDtls.StartDate)
                        </th>
                        @*<th>
                            @Html.DisplayNameFor(model => model.HrmPsCommandDtls.NewPosId)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.HrmPsCommandDtls.NewClassId)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.HrmPsCommandDtls.NewExecName)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.HrmPsCommandDtls.NewJobSiteId)
                        </th>
                        <th>
                            @Html.DisplayNameFor(model => model.HrmPsCommandDtls.NewWorkingJobSiteId)
                        </th>*@
                        <th>

                        </th>
                    </tr>
                </thead>
                <tbody>
                @foreach (var item in Model.col_hrm_ps_command_dtls)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.HrmPsEmployees.FullName)
                        </td>
                        <td>
                            @(item.StartDate.HasValue ? item.StartDate.Value.ToLongDateString() : "")
                        </td>
                        @*<td>
                            @Html.DisplayFor(model => item.NewPosRef) : @Html.DisplayFor(model => item.NewPosName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.new_hrm_mp_classes.class_name)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.NewExecName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.NewJobSiteName)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.NewWorkingJobSiteName)
                        </td>*@
                        <td>
                            @if (Model.RecordStatus != "A" && Model.RecordStatus != "P")
                            {
                            <a id="lnkEditDetail@(item.CmdDtlsId)" title="คลิกเพื่อแก้ไขรายชื่อบุคลากรในคำสั่ง">แก้ไข</a>@Html.Raw("&nbsp;&nbsp;|&nbsp;&nbsp;")
                            @Html.ActionLink("ลบ", "DetailDelete", new { id = item.CmdDtlsId, model = item }, new { id="lnkDelete"+item.CmdId, onclick="var ans = confirm('ต้องการลบ ใช่หรือไม่?');if (!ans) return false;" })
                            }
                        </td>
                    </tr>
                }
                </tbody>

            </table>
        }
        
    </div>
}
</div>

<div style="padding-left:100px; margin-bottom:30px;width:800px;" >
    <div id="pnlDetailInfo" hidden>
        @{Html.RenderPartial("../CommandMove/CreateDetail", Model.CreateDetail());}
        </div>
    <div id="pnlEditDetailInfo" hidden>
        @{Html.RenderPartial("../CommandMove/EditDetail", Model.HrmPsCommandDtls);}
    </div>
</div>

@section Scripts {
    <script type="text/javascript" >
        jQuery(function ($) {
            $("input#approved_type").change(function () {
                $("#divApproverInternal").toggle(this.value == "1");
                $("#divApproverExternal").toggle(this.value == "2");
            });
            $("input#approved_type:checked").change();
        });

        function ddlPenaltyChange(e) {
            var comboBox = $("#PenaltyId").data("tComboBox");
            $("[id^='lblCmdTypeName']").text('โทษ>' + comboBox.text());
        }

        function ddlEmpChange(e) {
            $.getJSON('@Url.Action("GetEmployeeForCommandDetail", "Employee")', { 'id': e.value }, function (data) {
                $("#OldPosId").val(data.pos_seq);
                $("#OldPosRef").val(data.PosNo);
                $("#OldPosName").val(data.pos_name);
                $("#OldClassId").val(data.class_seq);
                $("#old_hrm_mp_classes_class_name").val(data.class_name);
                $("#old_exec_name").val(data.exec_name);
                $("#OldJobSiteId").val(data.JobSiteId);
                $("#OldJobSiteName").val(data.job_site_name);
                $("#OldWorkingJobSiteId").val(data.working_JobSiteId);
                $("#OldWorkingJobSiteName").val(data.working_job_site_name);
                $("#old_salary").val(data.salary);
            });
        }

        function ddlNewPosChange(e) {
            var ddl = $("#NewPosId-input").val().split(" : ");
            $("#NewPosRef").val(ddl[0]);
            $("#NewPosName").val(ddl[1]);
        }
        //function ddlNewClassChange(e) {
            
        //    $("#new_class_name").val($("#NewClassId-input").val());
        //}
        function ddlNewExecChange(e) {
            $("#NewExecName").val($("#NewExecName-input").val());
        }
        function ddlNewJobSiteChange(e) {
            $("#NewJobSiteName").val($("#NewJobSiteId-input").val());
        }
        function ddlNewWorkingJobSiteChange(e) {
            $("#NewWorkingJobSiteName").val($("#NewWorkingJobSiteId-input").val());
        }

        jQuery(function ($) {
            $("#lnkAddDetail").click(function () {
                //$("#lnkAddDetail").hide();
                $("#pnlHeader").hide("slide", { direction: "left" }, 300, function () {
                    $("#pnlDetailInfo").show("slide", { direction: "right" }, 300)
                });
            });

            //$("#lnkAddDetail").show();
            $("#pnlHeader").show("slide", { direction: "left" }, 300);
            $("#pnlDetailInfo").hide();
            $("#pnlEditDetailInfo").hide();

            $("[id^=lnkEditDetail]").click(function (event) {
                //var id = $("#CmdDtlsSeq").val();
                $.getJSON('@Url.Action("GetDetail", "CommandPenalty")', { 'id': event.target.id.replace("lnkEditDetail", "") }, function (data) {


                    var CmdId = $("#EditInfo").find("#CmdId");
                    var CmdDtlsId = $("#EditInfo").find("#CmdDtlsId");
                    var EmpId = $("#EditInfo").find("#EmpId");
                    var StartDate = $("#EditInfo").find("#StartDate");
                    var EndDate = $("#EditInfo").find("#EndDate");
                    var Remarks = $("#EditInfo").find("#Remarks");
                    var RptRemarks = $("#EditInfo").find("#RptRemarks");

                    CmdId.val(data.CmdId);
                    CmdDtlsId.val(data.CmdDtlsId);
                    EmpId.val(data.EmpId);
                    StartDate.val(data.StartDate);
                    EndDate.val(data.EndDate);
                    Remarks.val(data.Remarks);
                    RptRemarks.val(data.RptRemarks);

                });
                //$("#lnkAddDetail").hide();
                $("#pnlHeader").hide("slide", { direction: "left" }, 300, function () {
                    $("#pnlEditDetailInfo").show("slide", { direction: "right" }, 300)
                });
                //$("#pnlDetailInfo").hide({ speed: 500 })
            });

            $("#lnkCancel").click(function () {

                $("#pnlDetailInfo").hide("slide", { direction: "right" }, 300, function () {
                    $("#pnlHeader").show("slide", { direction: "left" }, 300)
                });
                //$("#lnkAddDetail").show();
            });

            $("#lnkEditCancel").click(function () {

                $("#pnlEditDetailInfo").hide("slide", { direction: "right" }, 300, function () {
                    $("#pnlHeader").show("slide", { direction: "left" }, 300)
                });
                //$("#lnkAddDetail").show();
            });
        });

        jQuery(function ($) {
            $("[type='submit']").click(function () {
                var ans = confirm("ต้องการบันทึก ใช่หรือไม่?");

                if (!ans) return false;
            });
        })

        jQuery(function ($) {
            $(".datepicker").datepicker({
                showOn: "focus",
                buttonImage: "../../Images/Icons/calendar.png",
                buttonImageOnly: true,
                dateFormat: "dd/mm/yy",
                isBE: true
            });
        });

        jQuery(function ($) {
            $("table.tablesorter").tablesorter({ widthFixed: true, sortList: [[0, 0]], widgets: ["zebra", "filter"] });
                //.tablesorterPager({ container: $("#pager"), size: $(".pagesize option:selected").val() });
        });
    </script>
}